// post.js
// pages/upload/upload.js
Page({
  data: {
    mediaList: [],
    categories: ['生活分享', '经验交流', '问答求助', '二手交易', '活动召集'],
    activeCategory: -1
  },

  handleClose() {
    wx.navigateBack()
  },

  handleAddMedia() {
    // 模拟媒体添加
    const newMedia = [...this.data.mediaList]
    if(newMedia.length < 9) {
      newMedia.push('https://via.placeholder.com/200x200.png/4a90e2/ffffff?text=Preview')
      this.setData({ mediaList: newMedia })
    }
  },

  handleDeleteMedia(e) {
    const index = e.currentTarget.dataset.index
    const newMedia = this.data.mediaList.filter((_,i) => i !== index)
    this.setData({ mediaList: newMedia })
  },

  selectCategory(e) {
    const index = e.currentTarget.dataset.index
    this.setData({ activeCategory: index === this.data.activeCategory ? -1 : index })
  }
})